package cn.com.yiqi.wsc.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 
 * @author Hxdong
 *
 */
public class MD5Util {

	public static String paseMD5(String str){
		
		 MessageDigest alg = null;
		 try {
		 alg = MessageDigest.getInstance("MD5");
		 } catch (NoSuchAlgorithmException e) {
		 e.printStackTrace();
		 }
		 alg.update(str.getBytes());
		 byte[] digesta = alg.digest();
		 return byte2Hex(digesta);
	}
	
	//转换下
	private static String byte2Hex(byte[] paramArrayOfByte) {
		 StringBuffer localStringBuffer = new StringBuffer();
		 String str = "";
		 for (int i = 0; i < paramArrayOfByte.length; ++i) {
		 str = Integer.toHexString(paramArrayOfByte[i] & 0xFF);
		 if (str.length() == 1)
		 localStringBuffer.append("0");
		 localStringBuffer.append(str);
		 }
		 return localStringBuffer.toString().toUpperCase();
	}
	
	public static void main(String arg[]) {
	     System.out.println(MD5Util.paseMD5("我"));
	
	}
	
}
